package com.wwmz.pattern.singleton.job;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by wumz on 2020/9/17 15:10
 */
@SuppressWarnings("all")
public class JobContainerSingleton {

    private JobContainerSingleton(){}

    private static Map<String, Object> ioc = new ConcurrentHashMap<>();

    public static Object getBean(String className){
        if(!ioc.containsKey(className)){
            synchronized (ioc){
                if (!ioc.containsKey(className)){
                    Object obj = null;
                    try {
                        obj = Class.forName(className).newInstance();
                        ioc.put(className, obj);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                    return obj;
                }
            }
        }
        return ioc.get(className);
    }
}
